{include file="Public:header2"/}
<body style="min-height: 100%;background-color: #fff">
<div style="padding: 0 20px;position: relative;z-index: 99;border-bottom: 1px solid #e5e5e5;line-height: 39px;height: 39px;overflow: hidden;">
      <span style="visibility: visible;">
        <a href="{:url('/admin/task_list')}" style="padding-right: 8px;line-height: 22px;font-size: 14px;color: #333!important;">任务管理<span class="layui-box">&gt;</span></a>
        <a href="javascript:;"> <cite>编辑任务</cite></a>
      </span>
</div>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <form onsubmit="return false;">
                        <div class="layui-form" wid100 lay-filter="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">任务分类</label>
                                <div class="layui-input-inline" style="width: 700px">
                                    <input type="radio" name="type" value="1" lay-filter="type" class="layui-input" title="每日任务" {if $data.type eq 1} checked {/if}>
                                    <input type="radio" name="type" value="2" lay-filter="type" class="layui-input" title="每周任务" {if $data.type eq 2} checked {/if}>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">任务种类</label>
                                <div class="layui-input-inline" style="width: 700px">
                                    <input type="radio" name="cate" value="1" lay-filter="type" class="layui-input" title="邀请好友注册" {if $data.cate eq 1} checked {/if}>
                                    <input type="radio" name="cate" value="2" lay-filter="type" class="layui-input" title="抽赏任务" {if $data.cate eq 2} checked {/if}>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">是否是重要任务</label>
                                <div class="layui-input-inline" style="width: 700px">
                                    <input type="radio" name="is_important" value="0" lay-filter="type" class="layui-input" title="否" {if $data.is_important eq 0} checked {/if}>
                                    <input type="radio" name="is_important" value="1" lay-filter="type" class="layui-input" title="是" {if $data.is_important eq 1} checked {/if}>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">任务名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="title" value="{$data['title']}" lay-verify="required" placeholder="请输入任务名称" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">排序</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="sort" value="{$data['sort']}" placeholder="请输入排序" autocomplete="off" class="layui-input"  style="width: 600px">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">需要完成任务几次</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="number" value="{$data['number']}" placeholder="请输入需要完成任务几次" autocomplete="off" class="layui-input"  style="width: 600px">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">赠送多少积分</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="z_number" value="{$data['z_number']}" placeholder="请输入赠送多少积分" autocomplete="off" class="layui-input"  style="width: 600px">
                                </div>
                            </div>
                            <input type="hidden" name="id" value="{$data['id']}">
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" onclick="return check()">确认保存</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="Public:footer"/}
</body>
</html>
<script type="text/javascript">
    layui.use(['layer','form','upload','laydate'], function(){
        var $ = layui.$;
        var form = layui.form;
        var upload = layui.upload;
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#arrive_time' //指定元素
            ,type : 'date'
            ,trigger : 'click'
        });

        //执行实例
        var uploadInst = upload.render({
            accept:'imgurl'
            ,elem: '#imgurl' //绑定元素
            ,url: '/admin/picture' //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.status == 1){ //成功
                    layer.msg("上传成功",{icon:1,time:1000},function(){
                        $("#imgurl").attr("src",res.data.path);  //单图
                        $("input[name=imgurl]").val(res.data.imgurl);
                    });
                }else{ //失败
                    layer.msg(res.msg,{icon:2,anim:6,time:1500});
                }
            }
            ,error: function(){
                //请求异常回调
                layer.msg('服务繁忙，请稍后再试',{icon:2,anim:6,time:1500});
            }
        });

         //选择是否发货
        form.on('radio(is_yu)', function(data){
          // console.log(data.elem); //得到 radio 原始 DOM 对象
          // console.log(data.value); //被点击的 radio 的 value 值
          if(data.value == 1 ){
            $('.arrive_time').hide();
          }else{
            $('.arrive_time').show();
          }
        });
        
    });

    function check(){
        var url="{:url('/admin/task_list_edit')}";
        var $ = layui.$;
        var load=layer.load(2);
        $.post(url,$("form").serialize(),function(data){
            if(data.status==1){
                layer.msg(data.msg,{icon:1,time:1000},function(){
                    location.href="{:url('/admin/task_list')}";
                });
            }else{
                layer.msg(data.msg,{icon:2,anim:6,time:1500},function(){
                    layer.close(load);
                });
            }
        })
    }
</script>
